#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:todolistviews.py
# author:jackiex
# datetime:2021/6/11 15:50
# software: PyCharm
'''
    todolist模块的蓝图定义
'''
from flask import Blueprint
from flask import render_template, request, redirect

todolist_bp = Blueprint("todolist", __name__, url_prefix="/test")  # 初始化蓝图

# web前端路由--纯静态页面渲染
@todolist_bp.route('/')
def home():
    # return render_template('index.html')
    return 'this is my web-flask index page from Blueprint!'

# web前端路由--传数据到前端
# @todolist_bp.route('/index')
# def index():
#     from controller.toDolistController import ToDoListController
#     res = ToDoListController.get_all()
#     return render_template('index.html', todolist=res['data'])

#定义添加处理路由
# @todolist_bp.route('/add',methods = ['POST'])
# def add():
#     from controller.toDolistController import ToDoListController
#     params = request.args if request.method == 'GET' else request.form
#     title = params.get('title')
#     print(title)
#     kwargs = {
#         'Title': title
#     }
#     ToDoListController.add(**kwargs)
#     return redirect('/todolist/index')
    # return render_template('index.html', todolist=res['data'])
    # return 'this is my web-flask index page!'

# 定义删除数据路由
# @todolist_bp.route('/delete/<AutoID>',methods=['POST','GET','DELETE'])
# def delete(AutoID):
#     from controller.toDolistController import ToDoListController
#     kwargs = {
#         'AutoID':AutoID
#     }
#     ToDoListController.delete(**kwargs)
#     return redirect('/todolist/index')

#定义查询方法
# @todolist_bp.route('/search',methods=['POST'])
# def search():
#     from controller.toDolistController import ToDoListController
#     params = request.args if request.method == 'GET' else request.form
#     title = params.get('title')
#     print(title)
#     kwargs = {
#         'Title': title,
#     }
#     res = ToDoListController.query(**kwargs)
#     return render_template('index.html', todolist=res['data'])

# web前端路由-ajax效果
# @todolist_bp.route('/ajax')
# def ajax():
#     return render_template('todolist_ajax.html')


# web前端路由--bootstrap模板效果
# @todolist_bp.route('/bootstrap')
# def bootstrap():
#     from controller.toDolistController import ToDoListController
#     todolist_res=ToDoListController.get_all()
#     return render_template('todolist_bootstrap.html',todolist=todolist_res['data'])


